package com.cy.controller;

import com.cy.NacosConfigApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName NacosConfigController
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/6/3 14:16
 * @Version V1.0
 **/
@RefreshScope
@RestController
public class NacosConfigController {

  /*@RefreshScope描述Controller类时,如果配置中心的配置发生变化
           当我们对此类中的url资源进行访问时会重新构建此对象*/

    public NacosConfigController(){
        System.out.println("NacosConfigController()");

    }
    @Value("${page.pageSize:5}")
    private Integer pageSize;

    @Value("${server.tomcat.threads.max:200}")
    private Integer serverThreadMax;

    private static Logger logger=
            LoggerFactory.getLogger(NacosConfigApplication.class);

    @Value("${logging.level.com.cy:error}")//这里的error表示没有取到日志级别
    private String logLevel;

//=================================================================================================================================================================

    @GetMapping("/config/doGetPageSize")
    public String doGetPageSize(){
        return "pageSize is "+pageSize;
    }

    @RequestMapping("/config/doGetServerThreadMax")
    public String doGetserverThreadMax(){
        return "server.threads.max is  "+serverThreadMax;
    }

    @GetMapping("/config/log/level")
    public String doPrintLogLevel(){
        System.out.println("log.level="+logLevel);

//debug<info<error,springboot默认日志级别为info
        //配合@RefreshScope测试根据配置中心的日志级别配置动态获取日志
        logger.info("==level.info==");
        logger.debug("==level.debug==");
        logger.error("==level.error==");

        return "log level is "+logLevel;
    }
}
